package com.mymaxis.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;




public class LogWriter {
 
	final static Logger logger = Logger.getLogger(LogWriter.class);
	static String newline = System.getProperty("line.separator");
	 
   
/*
    public static  void doLogging(String strReqID, String str1, String methodName, String str2, String logMsg) {
 	   
    		File log ;
    		Properties prop = new Properties();
    		InputStream  logFileProp = null;
    		SimpleDateFormat dt1 = new SimpleDateFormat("ddMMyyyy");
    		Date date = new Date();
    		//Sytem.out.println(dt1.format(date));
    		//File log = new File("C:/Documents and Settings/mebuser/Desktop/mymaxisapp"+dt1.format(date) + ".log");
    		//File log = new File("/app/cfi/v55/log/webservices/receiveWs123"+dt1.format(date) + ".log");
    		//File log = new File("/app/tomcat5.5/log/receiveWs_"+dt1.format(date) + ".log");
    		try{
    			
    			 Properties properties = new Properties();
				 properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("system.properties"));
				 String logFilePath = properties.getProperty("WsLogFile");
				 String logFileName = properties.getProperty("WsLogFileName");
				 log = new File(logFilePath + logFileName + dt1.format(date) +".log");
				 //Sytem.out.println("logFilePath :"+logFilePath);
				 //Sytem.out.println("logFileName :"+logFileName);
				 //Sytem.out.println("log :"+log);
				 
    		    if(!log.exists()){
    		        //Sytem.out.println("We had to make a new file.");
    		        log.createNewFile();
    		    }

    		    FileWriter fileWriter = new FileWriter(log, true);
    		    //fh.setFormatter(new SimpleFormatter());
    		    BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
    		    bufferedWriter.write(date+"(INFO) : REQID :"+ strReqID+","+"OPERATIONTYPE :"+methodName +","+"DATAOUT :"+logMsg);
    		    bufferedWriter.newLine();
    		    bufferedWriter.close();

    		    //Sytem.out.println("Done ");
    		} catch(IOException e) {
    		    //Sytem.out.println("COULD NOT LOG!!");
    		}
    	  
    	   
    		
    	}
    */
	
	public static void doLogging(String strReqID, String str1, String methodName, String str2, String logMsg) {
	 
		StringBuffer sb = new StringBuffer();
		
		  //bufferedWriter.write(date+"(INFO) : REQID :"+ strReqID+","+"OPERATIONTYPE :"+methodName +","+"DATAOUT :"+logMsg);
		sb.append("strReqID :"+strReqID+","+"OPERATIONTYPE :"+methodName+","+"DATAOUT :"+logMsg);
		//sb.append(newline);
		///sb.append("methodName :"+methodName);
		//sb.append(newline);
		//sb.append("DATAOUT :"+logMsg);
		logger.log(Level.INFO,sb.toString());
		
	
		
		
		
	}
} 
